package com.cqeec.gams.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cqeec.gams.entity.Account;
import com.cqeec.gams.model.Function;
import com.cqeec.gams.service.AccountService;

@Controller
public class MainController {
	@Autowired
	private AccountService accoutService;

	@RequestMapping("/main.html")
	public ModelAndView gotoMainPage(HttpSession session) {
		ModelAndView mav = new ModelAndView("main");
		// 根据登录的用户读取用户的权限（功能模块）
		// 获取登录用户的ID
		Object obj = session.getAttribute("user");
		if (obj == null) {
			// 没有用户的登录信息
			mav.setViewName("redirect:/login.html");
		} else {
			Account account = (Account) obj;
			List<Function> functions = accoutService.getUserFunction(account.getId());
			mav.addObject("functions", functions);
		}
		return mav;
	}
}
